﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Diagnostics;

namespace CFScript.Tasks
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Set:Task
    {
        public Set()
        {
            this.name = "<set>";
            this.parameterNames = new string[] {"name","value","type"};
            this.parameterExpandable = new bool[] { false, true, false };
            this.parameterRequired = new bool[] {true, false, false};
            this.parameters = new Dictionary<string, Parameter>();

            Debug.Assert(this.parameterNames.Length == this.parameterRequired.Length &&
                         this.parameterRequired.Length == this.parameterRequired.Length);
        }

        public override InstructionResult Execute(CFScript context)
        {
            InstructionResult result = new InstructionResult();
            result.ExecutedInstruction = this;

            Variable v = Variable.VariableFactory(this.parameters["name"].GetValue(context),
                                                  this.parameters["value"].GetValue(context),
                                                  this.parameters["type"].GetValue(context));
            context.AddVariable(v);

            result.BreakExecution = result.Code == ResultCode.ERROR && this.options.OnError == OnErrorAction.BREAK;

            return result;
        }

        
    }
}
